import request from '@/utils/request'

/**
 * 异常处理管理API接口
 */

// 分页查询异常记录列表
export function getExceptionHandlingPage(currentPage, pageSize, queryData) {
  return request({
    url: `/api/exception-handlings/page/${currentPage}/${pageSize}`,
    method: 'get',
    params: queryData
  })
}

// 条件查询异常记录
export function searchExceptionHandlings(queryData) {
  return request({
    url: '/api/exception-handlings/search',
    method: 'post',
    data: queryData
  })
}

// 根据ID查询异常记录详情
export function getExceptionHandlingById(exceptionId) {
  return request({
    url: `/api/exception-handlings/${exceptionId}`,
    method: 'get'
  })
}

// 处理异常记录
export function handleException(exceptionId, handleData) {
  return request({
    url: `/api/exception-handlings/${exceptionId}/handle`,
    method: 'post',
    data: handleData
  })
}

// 批量处理异常记录
export function batchHandleExceptions(exceptionIds, handleData) {
  return request({
    url: '/api/exception-handlings/batch-handle',
    method: 'post',
    data: {
      exceptionIds,
      ...handleData
    }
  })
}

// 获取异常处理统计信息
export function getExceptionHandlingStatistics(queryData) {
  return request({
    url: '/api/exception-handlings/statistics',
    method: 'get',
    params: queryData
  })
}

// 获取异常类型分布统计
export function getExceptionTypeStatistics(timeRange) {
  return request({
    url: '/api/exception-handlings/statistics/exception-type',
    method: 'get',
    params: { timeRange }
  })
}

// 获取异常级别统计
export function getExceptionLevelStatistics(timeRange) {
  return request({
    url: '/api/exception-handlings/statistics/exception-level',
    method: 'get',
    params: { timeRange }
  })
}

// 获取异常趋势分析数据
export function getExceptionTrendStatistics(timeRange) {
  return request({
    url: '/api/exception-handlings/statistics/trend',
    method: 'get',
    params: { timeRange }
  })
}

// 获取处理效率分析数据
export function getHandlingEfficiencyStatistics(timeRange) {
  return request({
    url: '/api/exception-handlings/statistics/handling-efficiency',
    method: 'get',
    params: { timeRange }
  })
}

// 获取异常处理报告
export function getExceptionHandlingReport(queryData) {
  return request({
    url: '/api/exception-handlings/report',
    method: 'post',
    data: queryData,
    responseType: 'blob'
  })
}

// 导出异常记录
export function exportExceptionHandlings(queryData) {
  return request({
    url: '/api/exception-handlings/export',
    method: 'post',
    data: queryData,
    responseType: 'blob'
  })
}

// 批量删除异常记录
export function batchDeleteExceptionHandlings(exceptionIds) {
  return request({
    url: '/api/exception-handlings/batch',
    method: 'delete',
    data: exceptionIds
  })
}

// 删除单个异常记录
export function deleteExceptionHandling(exceptionId) {
  return request({
    url: `/api/exception-handlings/${exceptionId}`,
    method: 'delete'
  })
}

// 标记异常为已处理
export function markAsHandled(exceptionId, handleRemark) {
  return request({
    url: `/api/exception-handlings/${exceptionId}/mark-handled`,
    method: 'post',
    data: { handleRemark }
  })
}

// 标记异常为未处理
export function markAsUnhandled(exceptionId) {
  return request({
    url: `/api/exception-handlings/${exceptionId}/mark-unhandled`,
    method: 'post'
  })
}

// 获取异常处理历史
export function getExceptionHandlingHistory(exceptionId) {
  return request({
    url: `/api/exception-handlings/${exceptionId}/history`,
    method: 'get'
  })
}

// 添加异常处理记录
export function addHandlingRecord(exceptionId, recordData) {
  return request({
    url: `/api/exception-handlings/${exceptionId}/handling-record`,
    method: 'post',
    data: recordData
  })
}

// 获取未处理异常数量
export function getUnhandledExceptionCount() {
  return request({
    url: '/api/exception-handlings/unhandled-count',
    method: 'get'
  })
}

// 获取异常处理统计概览
export function getExceptionHandlingOverview() {
  return request({
    url: '/api/exception-handlings/overview',
    method: 'get'
  })
}

// 清理过期异常记录
export function cleanExpiredExceptions(days) {
  return request({
    url: '/api/exception-handlings/clean',
    method: 'delete',
    params: { days }
  })
}

// 获取异常关键词统计
export function getExceptionKeywordStatistics(timeRange) {
  return request({
    url: '/api/exception-handlings/statistics/keywords',
    method: 'get',
    params: { timeRange }
  })
}

// 获取模块异常统计
export function getModuleExceptionStatistics(timeRange) {
  return request({
    url: '/api/exception-handlings/statistics/module',
    method: 'get',
    params: { timeRange }
  })
}